home *** CD-ROM | disk | FTP | other *** search
- package javax.swing.plaf.basic;
-
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Insets;
- import java.awt.LayoutManager;
- import java.awt.Rectangle;
- import java.awt.event.FocusListener;
- import java.awt.event.ItemListener;
- import java.awt.event.KeyListener;
- import java.awt.event.MouseListener;
- import java.awt.event.MouseMotionListener;
- import java.beans.PropertyChangeListener;
- import javax.accessibility.Accessible;
- import javax.accessibility.AccessibleContext;
- import javax.swing.CellRendererPane;
- import javax.swing.ComboBoxEditor;
- import javax.swing.ComboBoxModel;
- import javax.swing.DefaultListCellRenderer;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JComponent;
- import javax.swing.JList;
- import javax.swing.JPopupMenu;
- import javax.swing.KeyStroke;
- import javax.swing.ListCellRenderer;
- import javax.swing.LookAndFeel;
- import javax.swing.SwingUtilities;
- import javax.swing.UIManager;
- import javax.swing.event.ListDataListener;
- import javax.swing.plaf.ComboBoxUI;
- import javax.swing.plaf.ComponentUI;
- import javax.swing.plaf.UIResource;
-
- public class BasicComboBoxUI extends ComboBoxUI {
- protected JComboBox comboBox;
- protected boolean hasFocus = false;
- private boolean lightNav = false;
- private static final String LIGHTWEIGHT_KEYBOARD_NAVIGATION = "JComboBox.lightweightKeyboardNavigation";
- private static final String LIGHTWEIGHT_KEYBOARD_NAVIGATION_ON = "Lightweight";
- private static final String LIGHTWEIGHT_KEYBOARD_NAVIGATION_OFF = "Heavyweight";
- protected JList listBox;
- protected CellRendererPane currentValuePane = new CellRendererPane();
- protected ComboPopup popup;
- protected Component editor;
- protected JButton arrowButton;
- protected KeyListener keyListener;
- protected FocusListener focusListener;
- FocusListener editorFocusListener;
- protected ItemListener itemListener;
- protected PropertyChangeListener propertyChangeListener;
- protected MouseListener popupMouseListener;
- protected MouseMotionListener popupMouseMotionListener;
- protected KeyListener popupKeyListener;
- protected ListDataListener listDataListener;
- protected boolean isMinimumSizeDirty = true;
- protected Dimension cachedMinimumSize = new Dimension(0, 0);
- Dimension cachedDisplaySize = new Dimension(0, 0);
- static DefaultListCellRenderer textRenderer = new DefaultListCellRenderer();
-
- // $FF: synthetic method
- static boolean access$0(BasicComboBoxUI var0) {
- return var0.lightNav;
- }
-
- // $FF: synthetic method
- static void access$1(BasicComboBoxUI var0, boolean var1) {
- var0.lightNav = var1;
- }
-
- public void addEditor() {
- this.removeEditor();
- this.editor = this.comboBox.getEditor().getEditorComponent();
- this.comboBox.add(this.editor);
- }
-
- public void configureArrowButton() {
- if (this.arrowButton != null) {
- this.arrowButton.setEnabled(this.comboBox.isEnabled());
- this.arrowButton.setRequestFocusEnabled(false);
- if (this.popupMouseListener != null) {
- this.arrowButton.addMouseListener(this.popupMouseListener);
- }
-
- if (this.popupMouseMotionListener != null) {
- this.arrowButton.addMouseMotionListener(this.popupMouseMotionListener);
- }
-
- this.arrowButton.resetKeyboardActions();
- }
-
- }
-
- protected void configureEditor() {
- this.editor.setFont(this.comboBox.getFont());
- if (this.popupKeyListener != null) {
- this.editor.addKeyListener(this.popupKeyListener);
- }
-
- if (this.editor instanceof Accessible) {
- AccessibleContext var1 = ((Accessible)this.editor).getAccessibleContext();
- if (var1 != null) {
- var1.setAccessibleParent(this.comboBox);
- }
- }
-
- this.comboBox.configureEditor(this.comboBox.getEditor(), this.comboBox.getSelectedItem());
- }
-
- protected JButton createArrowButton() {
- return new BasicArrowButton(5);
- }
-
- protected ComboBoxEditor createEditor() {
- return new BasicComboBoxEditor.UIResource();
- }
-
- protected FocusListener createFocusListener() {
- return new FocusHandler(this);
- }
-
- protected ItemListener createItemListener() {
- return new ItemHandler(this);
- }
-
- protected KeyListener createKeyListener() {
- return new KeyHandler(this);
- }
-
- protected LayoutManager createLayoutManager() {
- return new ComboBoxLayoutManager(this);
- }
-
- protected ListDataListener createListDataListener() {
- return new ListDataHandler(this);
- }
-
- protected ComboPopup createPopup() {
- BasicComboPopup var1 = new BasicComboPopup(this.comboBox);
- ((JPopupMenu)var1).getAccessibleContext().setAccessibleParent(this.comboBox);
- return var1;
- }
-
- protected PropertyChangeListener createPropertyChangeListener() {
- return new PropertyChangeHandler(this);
- }
-
- protected ListCellRenderer createRenderer() {
- return new BasicComboBoxRenderer.UIResource();
- }
-
- public static ComponentUI createUI(JComponent var0) {
- return new BasicComboBoxUI();
- }
-
- public Accessible getAccessibleChild(JComponent var1, int var2) {
- switch (var2) {
- case 0:
- if (this.popup instanceof Accessible) {
- AccessibleContext var4 = ((Accessible)this.popup).getAccessibleContext();
- var4.setAccessibleParent(this.comboBox);
- return (Accessible)this.popup;
- }
- break;
- case 1:
- if (this.comboBox.isEditable() && this.editor instanceof Accessible) {
- AccessibleContext var3 = ((Accessible)this.editor).getAccessibleContext();
- var3.setAccessibleParent(this.comboBox);
- return (Accessible)this.editor;
- }
- }
-
- return null;
- }
-
- public int getAccessibleChildrenCount(JComponent var1) {
- return this.comboBox.isEditable() ? 2 : 1;
- }
-
- protected Dimension getDefaultSize() {
- ListCellRenderer var1 = this.comboBox.getRenderer();
- Component var2 = textRenderer.getListCellRendererComponent(this.listBox, " ", -1, false, false);
- this.currentValuePane.add(var2);
- var2.setFont(this.comboBox.getFont());
- int var3 = var2.getPreferredSize().height;
- this.currentValuePane.remove(var2);
- return new Dimension(100, var3);
- }
-
- protected Dimension getDisplaySize() {
- if (this.comboBox.isEditable() && this.comboBox.getModel().getSize() == 0) {
- return new Dimension(100, this.editor.getPreferredSize().height);
- } else {
- Dimension var3 = new Dimension();
- ListCellRenderer var4 = this.comboBox.getRenderer();
- ComboBoxModel var5 = this.comboBox.getModel();
- if (var4 != null && var5.getSize() > 0) {
- int var1 = 0;
-
- for(int var2 = var5.getSize(); var1 < var2; ++var1) {
- Component var6 = var4.getListCellRendererComponent(this.listBox, var5.getElementAt(var1), -1, false, false);
- this.currentValuePane.add(var6);
- var6.setFont(this.comboBox.getFont());
- Dimension var7 = var6.getPreferredSize();
- this.currentValuePane.remove(var6);
- var3.width = Math.max(var3.width, var7.width);
- var3.height = Math.max(var3.height, var7.height);
- }
-
- if (this.comboBox.isEditable()) {
- Dimension var8 = this.editor.getPreferredSize();
- var3.width = Math.max(var3.width, var8.width);
- var3.height = Math.max(var3.height, var8.height);
- }
-
- this.cachedDisplaySize.setSize(var3.width, var3.height);
- return var3;
- } else {
- return this.getDefaultSize();
- }
- }
- }
-
- protected Insets getInsets() {
- return this.comboBox.getInsets();
- }
-
- public Dimension getMaximumSize(JComponent var1) {
- Dimension var2 = this.getPreferredSize(var1);
- var2.width = 32767;
- return var2;
- }
-
- public Dimension getMinimumSize(JComponent var1) {
- if (!this.isMinimumSizeDirty) {
- return new Dimension(this.cachedMinimumSize);
- } else {
- Insets var3 = this.getInsets();
- Dimension var2 = this.getDisplaySize();
- var2.height += var3.top + var3.bottom;
- int var4 = var2.height - (var3.top + var3.bottom);
- var2.width += var3.left + var3.right + var4;
- this.cachedMinimumSize.setSize(var2.width, var2.height);
- this.isMinimumSizeDirty = false;
- return var2;
- }
- }
-
- public Dimension getPreferredSize(JComponent var1) {
- Dimension var2 = this.getMinimumSize(var1);
- var2.width += 4;
- return var2;
- }
-
- protected void installComponents() {
- this.arrowButton = this.createArrowButton();
- this.comboBox.add(this.arrowButton);
- if (this.comboBox.isEditable()) {
- this.addEditor();
- }
-
- this.comboBox.add(this.currentValuePane);
- }
-
- protected void installDefaults() {
- LookAndFeel.installColorsAndFont(this.comboBox, "ComboBox.background", "ComboBox.foreground", "ComboBox.font");
- LookAndFeel.installBorder(this.comboBox, "ComboBox.border");
- }
-
- protected void installKeyboardActions() {
- 3 var1 = new 3(this);
- this.comboBox.registerKeyboardAction(var1, KeyStroke.getKeyStroke(27, 0), 1);
- this.comboBox.registerKeyboardAction(new 1.KeyToListDispatcher(this, 33), KeyStroke.getKeyStroke(33, 0), 1);
- this.comboBox.registerKeyboardAction(new 1.KeyToListDispatcher(this, 34), KeyStroke.getKeyStroke(34, 0), 1);
- this.comboBox.registerKeyboardAction(new 1.KeyToListDispatcher(this, 36), KeyStroke.getKeyStroke(36, 0), 1);
- this.comboBox.registerKeyboardAction(new 1.KeyToListDispatcher(this, 35), KeyStroke.getKeyStroke(35, 0), 1);
- }
-
- protected void installListeners() {
- if ((this.itemListener = this.createItemListener()) != null) {
- this.comboBox.addItemListener(this.itemListener);
- }
-
- if ((this.propertyChangeListener = this.createPropertyChangeListener()) != null) {
- this.comboBox.addPropertyChangeListener(this.propertyChangeListener);
- }
-
- if ((this.keyListener = this.createKeyListener()) != null) {
- this.comboBox.addKeyListener(this.keyListener);
- }
-
- if ((this.focusListener = this.createFocusListener()) != null) {
- this.comboBox.addFocusListener(this.focusListener);
- }
-
- if ((this.popupMouseListener = this.popup.getMouseListener()) != null) {
- this.comboBox.addMouseListener(this.popupMouseListener);
- }
-
- if ((this.popupMouseMotionListener = this.popup.getMouseMotionListener()) != null) {
- this.comboBox.addMouseMotionListener(this.popupMouseMotionListener);
- }
-
- if ((this.popupKeyListener = this.popup.getKeyListener()) != null) {
- this.comboBox.addKeyListener(this.popupKeyListener);
- }
-
- if (this.comboBox.getModel() != null && (this.listDataListener = this.createListDataListener()) != null) {
- this.comboBox.getModel().addListDataListener(this.listDataListener);
- }
-
- }
-
- public void installUI(JComponent var1) {
- this.isMinimumSizeDirty = true;
- this.comboBox = (JComboBox)var1;
- this.installDefaults();
- this.popup = this.createPopup();
- this.listBox = this.popup.getList();
- Object var2 = var1.getClientProperty("JComboBox.lightweightKeyboardNavigation");
- if (var2 != null) {
- if (var2.equals("Lightweight")) {
- this.lightNav = true;
- } else if (var2.equals("Heavyweight")) {
- this.lightNav = false;
- }
- }
-
- if (this.comboBox.getRenderer() == null || this.comboBox.getRenderer() instanceof UIResource) {
- this.comboBox.setRenderer(this.createRenderer());
- }
-
- if (this.comboBox.getEditor() == null || this.comboBox.getEditor() instanceof UIResource) {
- this.comboBox.setEditor(this.createEditor());
- }
-
- this.installComponents();
- this.installListeners();
- if (this.arrowButton != null) {
- this.configureArrowButton();
- }
-
- if (this.editor != null) {
- this.configureEditor();
- }
-
- this.comboBox.setLayout(this.createLayoutManager());
- this.comboBox.setRequestFocusEnabled(true);
- 1 var3 = new 1(this);
- SwingUtilities.invokeLater(var3);
- }
-
- public boolean isFocusTraversable(JComboBox var1) {
- return this.comboBox.isEditable() ^ true;
- }
-
- protected boolean isNavigationKey(int var1) {
- return var1 == 38 || var1 == 40 || var1 == KeyStroke.getKeyStroke("KP_UP").getKeyCode() || var1 == KeyStroke.getKeyStroke("KP_DOWN").getKeyCode();
- }
-
- public boolean isPopupVisible(JComboBox var1) {
- return this.popup.isVisible();
- }
-
- public void paint(Graphics var1, JComponent var2) {
- this.hasFocus = this.comboBox.hasFocus();
- if (!this.comboBox.isEditable()) {
- Rectangle var3 = this.rectangleForCurrentValue();
- this.paintCurrentValueBackground(var1, var3, this.hasFocus);
- this.paintCurrentValue(var1, var3, this.hasFocus);
- }
-
- }
-
- public void paintCurrentValue(Graphics var1, Rectangle var2, boolean var3) {
- ListCellRenderer var4 = this.comboBox.getRenderer();
- if (this.comboBox.getSelectedIndex() != -1) {
- Component var5;
- if (var3 && !this.isPopupVisible(this.comboBox)) {
- var5 = var4.getListCellRendererComponent(this.listBox, this.comboBox.getSelectedItem(), -1, true, false);
- } else {
- var5 = var4.getListCellRendererComponent(this.listBox, this.comboBox.getSelectedItem(), -1, false, false);
- var5.setBackground(UIManager.getColor("ComboBox.background"));
- }
-
- var5.setFont(this.comboBox.getFont());
- if (var3 && !this.isPopupVisible(this.comboBox)) {
- var5.setForeground(this.listBox.getSelectionForeground());
- var5.setBackground(this.listBox.getSelectionBackground());
- } else if (this.comboBox.isEnabled()) {
- var5.setForeground(this.comboBox.getForeground());
- var5.setBackground(this.comboBox.getBackground());
- } else {
- var5.setForeground(UIManager.getColor("ComboBox.disabledForeground"));
- var5.setBackground(UIManager.getColor("ComboBox.disabledBackground"));
- }
-
- this.currentValuePane.paintComponent(var1, var5, this.comboBox, var2.x, var2.y, var2.width, var2.height);
- }
- }
-
- public void paintCurrentValueBackground(Graphics var1, Rectangle var2, boolean var3) {
- Color var4 = var1.getColor();
- if (this.comboBox.isEnabled()) {
- var1.setColor(UIManager.getColor("ComboBox.background"));
- } else {
- var1.setColor(UIManager.getColor("ComboBox.disabledBackground"));
- }
-
- var1.fillRect(var2.x, var2.y, var2.width, var2.height);
- var1.setColor(var4);
- }
-
- protected Rectangle rectangleForCurrentValue() {
- int var1 = this.comboBox.getWidth();
- int var2 = this.comboBox.getHeight();
- Insets var3 = this.getInsets();
- int var4 = var2 - (var3.top + var3.bottom);
- if (this.arrowButton != null) {
- var4 = this.arrowButton.getWidth();
- }
-
- return new Rectangle(var3.left, var3.top, var1 - (var3.left + var3.right + var4), var2 - (var3.top + var3.bottom));
- }
-
- public void removeEditor() {
- if (this.editor != null) {
- this.unconfigureEditor();
- this.comboBox.remove(this.editor);
- }
-
- }
-
- void repaintCurrentValue() {
- Rectangle var1 = this.rectangleForCurrentValue();
- this.comboBox.repaint(var1.x, var1.y, var1.width, var1.height);
- }
-
- protected void selectNextPossibleValue() {
- int var1;
- if (this.lightNav) {
- var1 = this.listBox.getSelectedIndex();
- } else {
- var1 = this.comboBox.getSelectedIndex();
- }
-
- if (var1 < this.comboBox.getModel().getSize() - 1) {
- if (this.lightNav) {
- this.listBox.setSelectedIndex(var1 + 1);
- this.listBox.ensureIndexIsVisible(var1 + 1);
- } else {
- this.comboBox.setSelectedIndex(var1 + 1);
- }
-
- this.comboBox.repaint();
- }
-
- }
-
- protected void selectPreviousPossibleValue() {
- int var1;
- if (this.lightNav) {
- var1 = this.listBox.getSelectedIndex();
- } else {
- var1 = this.comboBox.getSelectedIndex();
- }
-
- if (var1 > 0) {
- if (this.lightNav) {
- this.listBox.setSelectedIndex(var1 - 1);
- this.listBox.ensureIndexIsVisible(var1 - 1);
- } else {
- this.comboBox.setSelectedIndex(var1 - 1);
- }
-
- this.comboBox.repaint();
- }
-
- }
-
- public void setPopupVisible(JComboBox var1, boolean var2) {
- if (var2) {
- this.popup.show();
- } else {
- this.popup.hide();
- }
-
- }
-
- protected void toggleOpenClose() {
- this.setPopupVisible(this.comboBox, this.isPopupVisible(this.comboBox) ^ true);
- }
-
- public void unconfigureArrowButton() {
- if (this.arrowButton != null) {
- if (this.popupMouseListener != null) {
- this.arrowButton.removeMouseListener(this.popupMouseListener);
- }
-
- if (this.popupMouseMotionListener != null) {
- this.arrowButton.removeMouseMotionListener(this.popupMouseMotionListener);
- }
- }
-
- }
-
- protected void unconfigureEditor() {
- if (this.popupKeyListener != null) {
- this.editor.removeKeyListener(this.popupKeyListener);
- }
-
- }
-
- protected void uninstallComponents() {
- if (this.arrowButton != null) {
- this.unconfigureArrowButton();
- }
-
- if (this.editor != null) {
- this.unconfigureEditor();
- }
-
- this.comboBox.removeAll();
- this.arrowButton = null;
- }
-
- protected void uninstallDefaults() {
- LookAndFeel.installColorsAndFont(this.comboBox, "ComboBox.background", "ComboBox.foreground", "ComboBox.font");
- LookAndFeel.uninstallBorder(this.comboBox);
- }
-
- protected void uninstallKeyboardActions() {
- this.comboBox.unregisterKeyboardAction(KeyStroke.getKeyStroke(27, 0));
- this.comboBox.unregisterKeyboardAction(KeyStroke.getKeyStroke(33, 0));
- this.comboBox.unregisterKeyboardAction(KeyStroke.getKeyStroke(34, 0));
- this.comboBox.unregisterKeyboardAction(KeyStroke.getKeyStroke(36, 0));
- this.comboBox.unregisterKeyboardAction(KeyStroke.getKeyStroke(35, 0));
- }
-
- protected void uninstallListeners() {
- if (this.keyListener != null) {
- this.comboBox.removeKeyListener(this.keyListener);
- }
-
- if (this.itemListener != null) {
- this.comboBox.removeItemListener(this.itemListener);
- }
-
- if (this.propertyChangeListener != null) {
- this.comboBox.removePropertyChangeListener(this.propertyChangeListener);
- }
-
- if (this.focusListener != null) {
- this.comboBox.removeFocusListener(this.focusListener);
- }
-
- if (this.popupMouseListener != null) {
- this.comboBox.removeMouseListener(this.popupMouseListener);
- }
-
- if (this.popupMouseMotionListener != null) {
- this.comboBox.removeMouseMotionListener(this.popupMouseMotionListener);
- }
-
- if (this.popupKeyListener != null) {
- this.comboBox.removeKeyListener(this.popupKeyListener);
- }
-
- if (this.comboBox.getModel() != null && this.listDataListener != null) {
- this.comboBox.getModel().removeListDataListener(this.listDataListener);
- }
-
- }
-
- public void uninstallUI(JComponent var1) {
- this.setPopupVisible(this.comboBox, false);
- this.popup.uninstallingUI();
- this.uninstallKeyboardActions();
- this.comboBox.setLayout((LayoutManager)null);
- this.uninstallComponents();
- this.uninstallListeners();
- this.uninstallDefaults();
- if (this.comboBox.getRenderer() == null || this.comboBox.getRenderer() instanceof UIResource) {
- this.comboBox.setRenderer((ListCellRenderer)null);
- }
-
- if (this.comboBox.getEditor() == null || this.comboBox.getEditor() instanceof UIResource) {
- this.comboBox.setEditor((ComboBoxEditor)null);
- }
-
- this.keyListener = null;
- this.focusListener = null;
- this.listDataListener = null;
- this.popupKeyListener = null;
- this.popupMouseListener = null;
- this.popupMouseMotionListener = null;
- this.propertyChangeListener = null;
- this.popup = null;
- this.listBox = null;
- this.comboBox = null;
- }
-
- void updateToolTipTextForChildren() {
- Component[] var1 = this.comboBox.getComponents();
-
- for(int var2 = 0; var2 < var1.length; ++var2) {
- if (var1[var2] instanceof JComponent) {
- ((JComponent)var1[var2]).setToolTipText(this.comboBox.getToolTipText());
- }
- }
-
- }
- }
-